package com.crm.gzcrm.service.impl;

import com.crm.gzcrm.mapper.CourseOrderMapper;
import com.crm.gzcrm.model.CourseOrder;
import com.crm.gzcrm.model.MonthIncome;
import com.crm.gzcrm.model.PageResult;
import com.crm.gzcrm.service.ICourseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CourseOrderServiceImpl implements ICourseOrderService {

    @Autowired
    private CourseOrderMapper courseOrderMapper;

    @Override
    public PageResult<CourseOrder> findPageResult(CourseOrder condition, int page, int pageSize) {
        Map<String,Object> params = new HashMap<>();
        params.put("condition",condition);//模糊查询条件
        params.put("start",(page-1)*pageSize);
        params.put("pageSize",pageSize);

        PageResult<CourseOrder> result = new PageResult<>();

        result.setCount(courseOrderMapper.findCountByMap(params));
        result.setData(courseOrderMapper.findListByMap(params));
        return result;


      /*  //获取总记录数据
        int totalCount = courseOrderMapper.findCountByMap(params);
        result.setCount(totalCount);
        //获取查询的数据
        List<CourseOrder> list = courseOrderMapper.findListByMap(params);
        result.setData(list);



        return result;*/

    }

    @Override
    public void save(CourseOrder order) {
        courseOrderMapper.insert(order);
    }

    @Override
    public CourseOrder findByOrderId(String order_id) {
        return courseOrderMapper.findByOrderId(order_id);
    }

    @Override
    public void deleteByOrderId(String order_id) {
        courseOrderMapper.deleteByOrderId(order_id);
    }

    @Override
    public void update(CourseOrder order) {
        courseOrderMapper.update(order);
    }

    @Override
    public List<MonthIncome> getMonthIncomes() {
        return courseOrderMapper.getMonthIncomes();
    }
}
